package com.yuelife.service.controller;

import com.github.pagehelper.PageInfo;
import com.yuelife.service.pojo.SCommonClass;
import com.yuelife.service.service.SCommonClassService;
import entity.Result;
import entity.StatusCode;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/****
 * @Author:admin
 * @Description:
 * @Date 2019/6/14 0:18
 *****/
@Api(value = "SCommonClassController")
@RestController
@RequestMapping("/sCommonClass")
@CrossOrigin
public class SCommonClassController {

    @Autowired
    private SCommonClassService sCommonClassService;

    /***
     * SCommonClass分页条件搜索实现
     * @param sCommonClass
     * @param page
     * @param size
     * @return
     */
    @ApiOperation(value = "SCommonClass条件分页查询",notes = "分页条件查询SCommonClass方法详情",tags = {"SCommonClassController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false) @ApiParam(name = "SCommonClass对象",value = "传入JSON数据",required = false) SCommonClass sCommonClass, @PathVariable  int page, @PathVariable  int size){
        //调用SCommonClassService实现分页条件查询SCommonClass
        PageInfo<SCommonClass> pageInfo = sCommonClassService.findPage(sCommonClass, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * SCommonClass分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @ApiOperation(value = "SCommonClass分页查询",notes = "分页查询SCommonClass方法详情",tags = {"SCommonClassController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用SCommonClassService实现分页查询SCommonClass
        PageInfo<SCommonClass> pageInfo = sCommonClassService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param sCommonClass
     * @return
     */
    @ApiOperation(value = "SCommonClass条件查询",notes = "条件查询SCommonClass方法详情",tags = {"SCommonClassController"})
    @PostMapping(value = "/search" )
    public Result<List<SCommonClass>> findList(@RequestBody(required = false) @ApiParam(name = "SCommonClass对象",value = "传入JSON数据",required = false) SCommonClass sCommonClass){
        //调用SCommonClassService实现条件查询SCommonClass
        List<SCommonClass> list = sCommonClassService.findList(sCommonClass);
        return new Result<List<SCommonClass>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @ApiOperation(value = "SCommonClass根据ID删除",notes = "根据ID删除SCommonClass方法详情",tags = {"SCommonClassController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Integer")
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable Integer id){
        //调用SCommonClassService实现根据主键删除
        sCommonClassService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改SCommonClass数据
     * @param sCommonClass
     * @param id
     * @return
     */
    @ApiOperation(value = "SCommonClass根据ID修改",notes = "根据ID修改SCommonClass方法详情",tags = {"SCommonClassController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Integer")
    @PutMapping(value="/{id}")
    public Result update(@RequestBody @ApiParam(name = "SCommonClass对象",value = "传入JSON数据",required = false) SCommonClass sCommonClass, @PathVariable Integer id){
        //设置主键值
        sCommonClass.setCommonClassId(id);
        //调用SCommonClassService实现修改SCommonClass
        sCommonClassService.update(sCommonClass);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增SCommonClass数据
     * @param sCommonClass
     * @return
     */
    @ApiOperation(value = "SCommonClass添加",notes = "添加SCommonClass方法详情",tags = {"SCommonClassController"})
    @PostMapping
    public Result add(@RequestBody  @ApiParam(name = "SCommonClass对象",value = "传入JSON数据",required = true) SCommonClass sCommonClass){
        //调用SCommonClassService实现添加SCommonClass
        sCommonClassService.add(sCommonClass);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询SCommonClass数据
     * @param id
     * @return
     */
    @ApiOperation(value = "SCommonClass根据ID查询",notes = "根据ID查询SCommonClass方法详情",tags = {"SCommonClassController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Integer")
    @GetMapping("/{id}")
    public Result<SCommonClass> findById(@PathVariable Integer id){
        //调用SCommonClassService实现根据主键查询SCommonClass
        SCommonClass sCommonClass = sCommonClassService.findById(id);
        return new Result<SCommonClass>(true,StatusCode.OK,"查询成功",sCommonClass);
    }

    /***
     * 查询SCommonClass全部数据
     * @return
     */
    @ApiOperation(value = "查询所有SCommonClass",notes = "查询所SCommonClass有方法详情",tags = {"SCommonClassController"})
    @GetMapping
    public Result<List<SCommonClass>> findAll(){
        //调用SCommonClassService实现查询所有SCommonClass
        List<SCommonClass> list = sCommonClassService.findAll();
        return new Result<List<SCommonClass>>(true, StatusCode.OK,"查询成功",list) ;
    }
}
